package com.cwf.metadatamanage.model.vo;

import com.cwf.metadatamanage.enums.HttpCodeEnum;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@JsonIgnoreProperties
public class ResultResponse<T> {

    private int code = HttpCodeEnum.OK.getCode();
    private String msg;
    private T data;

    public ResultResponse success() {
        this.code = HttpCodeEnum.OK.getCode();
        this.msg = "Success";
        return this;
    }

    public ResultResponse success(T data) {
        this.code = HttpCodeEnum.OK.getCode();
        this.data = data;
        this.msg = "Success";
        return this;
    }

    public ResultResponse fail() {
        this.code = HttpCodeEnum.FAIL.getCode();
        this.msg = "Fail";
        return this;
    }

    public ResultResponse fail(int code) {
        this.code = code;
        this.msg = "Fail";
        return this;
    }

    public ResultResponse fail(int code, String msg) {
        this.code = code;
        this.msg = msg;
        return this;
    }

    public ResultResponse fail(String msg) {
        this.code = HttpCodeEnum.SERVER_ERROR.getCode();
        this.msg = msg;
        return this;
    }

}
